class CreateTourGroups < ActiveRecord::Migration
  def self.up
    create_table :tour_groups, :force => true do |t|
      t.string :number, :null => false
      t.integer :sequence, :null => false
      t.date :during_start
      t.date :during_end
      t.references :nationality
      t.integer :people, :default => 0, :null => false
      t.integer :children, :default => 0, :null => false
      t.references :customer
      t.references :owner
      t.decimal :revenue, :precision => 8, :scale => 2, :default => 0, :null => false
      t.decimal :profit, :precision => 8, :scale => 2, :default => 0, :null => false
      t.decimal :total_profit, :precision => 8, :scale => 2, :default => 0, :null => false
      t.string :summary
      t.timestamps
    end
    
    execute "ALTER TABLE tour_groups ADD CONSTRAINT tour_groups_uq_1 UNIQUE (number)"
    execute "ALTER TABLE tour_groups ADD CONSTRAINT fk_tour_group_nationality FOREIGN KEY (nationality_id) REFERENCES nationalities(id)"
    execute "ALTER TABLE tour_groups ADD CONSTRAINT fk_tour_group_customer FOREIGN KEY (customer_id) REFERENCES customers(id)"
    execute "ALTER TABLE tour_groups ADD CONSTRAINT fk_tour_group_owner FOREIGN KEY (owner_id) REFERENCES employees(id)"
  end

  def self.down
    drop_table :tour_groups
  end
end
